package com.JobFind.controller;

import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut;

import com.opensymphony.xwork2.ActionSupport;
import com.JobFind.logic.ICompanyLogic;
import com.JobFind.logic.IRecruitmentLogic;
import com.JobFind.DTO.BringDataDTO;
import com.JobFind.DTO.CompanyDTO;
import com.JobFind.DTO.RecruitmentDTO;
import com.JobFind.DTO.RecruitmentEasyDTO;
import com.JobFind.DTO.UserDTO;

public class CompanyController extends BaseAction {

	private static final long serialVersionUID = 1L;
	@Resource
	private IRecruitmentLogic recruitmentLogic;
	private ICompanyLogic companyLogic;
	private CompanyDTO companyDTO;
	private RecruitmentEasyDTO recruitmentEasyDTO;
	private RecruitmentDTO recruitmentDTO;
	private UserDTO userDTO;
	private BringDataDTO dataDTO;
	
	@Resource
	public void setCompanyLogic(ICompanyLogic companyLogic) {
		this.companyLogic = companyLogic;
	}
	public CompanyDTO getCompanyDTO() {
		return companyDTO;
	}
	public UserDTO getUserDTO() {
		return userDTO;
	}
	public void setUserDTO(UserDTO userDTO) {
		this.userDTO = userDTO;
	}
	public void setCompanyDTO(CompanyDTO companyDTO) {
		this.companyDTO = companyDTO;
	}
	public RecruitmentDTO getRecruitmentDTO() {
		return recruitmentDTO;
	}
	public void setRecruitmentDTO(RecruitmentDTO recruitmentDTO) {
		this.recruitmentDTO = recruitmentDTO;
	}
	public RecruitmentEasyDTO getRecruitmentEasyDTO() {
		return recruitmentEasyDTO;
	}
	public void setRecruitmentEasyDTO(RecruitmentEasyDTO recruitmentEasyDTO) {
		this.recruitmentEasyDTO = recruitmentEasyDTO;
	}
	public BringDataDTO getDataDTO() {
		return dataDTO;
	}
	public void setDataDTO(BringDataDTO dataDTO) {
		this.dataDTO = dataDTO;
	}
	public void getCompanySession() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.companyLogic.getCompanySession());
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	public void loginCheck() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.companyLogic.loginCheck(companyDTO.getCompanyLoginName(), companyDTO.getCompanyPwd()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void getJobList() throws Exception{
		PrintWriter out = getWriter();
		String sQuery="";
		try {
			String search = dataDTO.getSearchKey();
			if(!search.equals("")){
				sQuery = "and (recruitmentRemarks like '%" + search + "%' or recruitmentInfo like '%" + search + "%' or recruitmentPosition like '%" + search + "%' or recruitmentId like '%" + search + "%' or tbCompany.companyName like '%" + search + "%')";
			}
			out.println(this.recruitmentLogic.getJobList(userDTO.getUserId(),sQuery));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void getCompanyInfoById() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.companyLogic.getCompanyInfoById(companyDTO.getCompanyId(),1));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void getCompanyInfoByComId() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.companyLogic.getCompanyInfoById(companyDTO.getCompanyId(),2));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	public void getRecruitmentInfoById() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.recruitmentLogic.getRecruitmentInfoById(recruitmentEasyDTO.getRecruitmentId()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void logoutCheck() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.companyLogic.logoutCheck());
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void updateCompany() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.companyLogic.updateCompanyInfo(companyDTO));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void  modifyCompanyPwd() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.companyLogic.modifyCompanyPwd(companyDTO.getCompanyId(), companyDTO.getCompanyPwd()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void getRecruitByCompanyId() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.recruitmentLogic.getRecruitByCompanyId(companyDTO.getCompanyId()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void updateSomeRecritInfo() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.recruitmentLogic.updateSomeRecritInfo(recruitmentEasyDTO.getRecruitmentId(), recruitmentEasyDTO.getRecruitmentPosition(), recruitmentEasyDTO.getRecruitmentInfo(), recruitmentEasyDTO.getRecruitmentRemarks()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void deleJob() throws Exception{
		PrintWriter out = getWriter();
		try {
				out.println(this.recruitmentLogic.deleJob(recruitmentEasyDTO.getRecruitmentId()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void addRecritmentInfo() throws Exception{
		PrintWriter out = getWriter();
		try {
				out.println(this.recruitmentLogic.addRecritmentInfo(recruitmentDTO));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void updateCompanyLogo() throws Exception{
		PrintWriter out = getWriter();
		try {
				out.println(this.companyLogic.updateCompanyLogo(companyDTO.getCompanyLogo(),companyDTO.getCompanyId()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void regCheck() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.companyLogic.addCompany(companyDTO));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void getAllUncheckCompany() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.companyLogic.getAllUncheckCompany());
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void checkCompanyInfo() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.companyLogic.checkCompanyInfo(companyDTO.getCompanyId(), companyDTO.getCompanyStatus()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
}
